/* GUI CONVERTED from ecload.p (converter v1.76) Tue Dec 31 10:45:16 2002 */
/* ecload.p - PCO LOAD SUBROUTINE                                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.5 $                                                     */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.4      LAST EDIT: 04/20/94      MODIFIED BY: QZL *H358*  */
/* REVISION: 7.4      LAST EDIT: 10/27/94      MODIFIED BY: ame *H578*  */
/* REVISION: 7.4      LAST EDIT: 12/01/94      MODIFIED BY: QZL *H612*  */
/* REVISION: 7.4      LAST EDIT: 07/11/95      MODIFIED BY: qzl *H0F9*  */
/* REVISION: 7.4      LAST EDIT: 12/29/95      MODIFIED BY: qzl *H0J1*  */
/* REVISION: 7.4      LAST MODIFIED: 10/08/96   BY: *H0N2*  Russ Witt   */
/* REVISION: 8.6      LAST EDIT: 12/09/96       BY: Joe Gawel *K00C*    */
/* REVISION: 8.6      LAST EDIT: 01/23/97       BY: John Worden *K04Z*  */
/* REVISION: 8.6      LAST EDIT: 06/25/97       BY: Joe Gawel *K0F4*    */
/* REVISION: 8.6      LAST MODIFIED: 08/13/97   BY: Joe Gawel    *K0H5* */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane    */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 12/06/99   BY: *K24J* Jyoti Thatte */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.5 $    BY: Katie Hilbert         DATE: 12/27/02  ECO: *P0L8*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}

{ecrodef.i}  /* ECD2_DET SIDEFILE DEFINITIONS */

define input parameter dlfile as character format "x(46)"
                              label "Dump/Load File".
define input parameter repro  like mfc_logical.

define shared variable no_rec as integer format ">>>>>9" extent 9.
define stream ecinout.
define variable ecdnew   like mfc_logical.
define variable key_fld  as character extent 5.
define variable ecmstart like mfc_logical.
define variable filename as character format "x(8)".
define variable cmtindx  like ecm_cmtindx no-undo.

no_rec = 0.
key_fld = "".

input stream ecinout from value(dlfile) no-map.
ecmstart = no.

loop-b:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

   if not ecmstart then
      import stream ecinout
         key_fld[1]
         key_fld[2]
         key_fld[3]
         key_fld[4]
         key_fld[5].

   ecmstart = no.
   if key_fld[1] =  "type:end of file" then next loop-b.
   else if key_fld[1] = "" then do:
      input stream ecinout close.
      return.
   end.

   if key_fld[1] = "type:ecm_mstr" then do:
      if can-find (ecm_mstr where ecm_nbr = key_fld[2])
         or (not repro and not can-find(pct_mstr where
         pct_type = key_fld[3] and pct_dsgn_grp = key_fld[4]))
      then
      repeat: /* skip all records related to this PCO */
         import stream ecinout ^.
         import stream ecinout
            key_fld[1]
            key_fld[2]
            key_fld[3]
            key_fld[4]
            key_fld[5].
         if key_fld[1] = "type:ecm_mstr" or
            key_fld[1] = "type:end of file"
         then do:
            ecmstart = yes.
            cmtindx = 0.
            next loop-b.
         end.
      end.
      else do:
         create ecm_mstr.
         assign
            ecm_nbr    = key_fld[2]
            ecm_type   = key_fld[3]
            ecm_assign = key_fld[4].
         import stream ecinout
            ecm_mstr except ecm_nbr ecm_type ecm_assign.

         if repro then do:
            assign
               ecm_sub_date   = ?
               ecm_rel_date   = ?
               ecm_eff_date   = ?
               ecm_end_date   = ?
               ecm_close_date = ?
               ecm_appr_date  = ?
               ecm_batched    = no
               ecm_type       = ""
               ecm_assign     = ""
               ecm_approval   = ""
               ecm_reprocess  = yes.

            for each rsu_mstr
                  where rsu_doc_nbr = ecm_nbr exclusive-lock:
               for each rsud_det exclusive-lock  where rsud_index =
                     rsu_index:
                  delete rsud_det.
               end.
               delete rsu_mstr.
            end.
         end.

         if ecm_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecm_cmtindx = cmtindx.
         end.

         no_rec[1] = no_rec[1] + 1.
      end.
   end.

   else if substring(key_fld[1],1,13) = "type:ecd1_det" then do:
      if (can-find(ecd1_det
          where ecd1_nbr = key_fld[2] and
                ecd1_par = key_fld[3] and
                ecd1_comp = key_fld[4] and
                ecd1_ref = key_fld[5]))
         or (not can-find(pt_mstr where pt_part = key_fld[3]) and
         not can-find(bom_mstr where bom_par = key_fld[3]))
         or (not can-find(pt_mstr where pt_part = key_fld[4]) and
         not can-find(bom_mstr where bom_par = key_fld[4]))
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create ecd1_det.
         assign
            ecd1_nbr  = key_fld[2]
            ecd1_par  = key_fld[3]
            ecd1_comp = key_fld[4]
            ecd1_ref  = key_fld[5].
         import stream ecinout
            ecd1_det except ecd1_nbr ecd1_par
                            ecd1_comp ecd1_ref.
         if recid(ecd1_det) = -1 then.

         if ecd1_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecd1_cmtindx = cmtindx.
         end.

         no_rec[3] = no_rec[3] + 1.
      end.
   end.

   else if key_fld[1] = "type:ecd2_det" then do:
      if can-find(ecd2_det
                  where ecd2_nbr = key_fld[2] and
                        ecd2_routing = key_fld[3] and
                        ecd2_op = integer(key_fld[4]))
      then do:
         import stream ecinout ^.
         import stream ecinout ^. /* SKIP QAD_WKFL */
         cmtindx = 0.
         next loop-b.
      end.
      else do:

         create ecd2_det.
         assign
            ecd2_nbr      = key_fld[2]
            ecd2_routing  = key_fld[3]
            ecd2_op       = integer(key_fld[4]).
         import stream ecinout
            ecd2_det except ecd2_nbr ecd2_routing ecd2_op.
         if recid(ecd2_det) = -1 then.

         find first qad_wkfl
            where qad_wkfl.qad_key1 = "ecd2_det"
              and qad_wkfl.qad_key2 = string((key_fld[2]),"x(24)")
                                    + string((key_fld[3]),"x(18)")
                                    + string((string(key_fld[4])),"x(5)")
         exclusive-lock no-error.
         if not available qad_wkfl then do:
            create qad_wkfl.
            import stream ecinout qad_wkfl.
         end.

         if ecd2_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecd2_cmtindx = cmtindx.
         end.

         no_rec[5] = no_rec[5] + 1.
      end.
   end.

   else if key_fld[1] = "type:ecd3_det" then do:
      if can-find(ecd3_det where ecd3_nbr = key_fld[2] and
                  ecd3_cmtindx = integer(key_fld[3]))
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create ecd3_det.
         assign
            ecd3_nbr  = key_fld[2]
            ecd3_cmtindx  = integer(key_fld[3]).
         import stream ecinout
            ecd3_det except ecd3_nbr ecd3_cmtindx.
         if recid(ecd3_det) = -1 then.

         if ecd3_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecd3_cmtindx = cmtindx.
         end.

         no_rec[2] = no_rec[2] + 1.
      end.
   end.
   else if key_fld[1] = "type:ecd4_det" then do:
      if can-find(ecd4_det where ecd4_nbr = key_fld[2] and
                  ecd4_cmtindx = integer(key_fld[3]))
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create ecd4_det.
         assign
            ecd4_nbr  = key_fld[2]
            ecd4_cmtindx  = integer(key_fld[3]).
         import stream ecinout
            ecd4_det except ecd4_nbr ecd4_cmtindx.
         if recid(ecd4_det) = -1 then.
         if ecd4_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecd4_cmtindx = cmtindx.
         end.

         no_rec[9] = no_rec[9] + 1.
      end.
   end.

   else if key_fld[1] = "type:rsu_mstr" then do:
      find ecm_mstr where ecm_nbr = key_fld[2] no-lock no-error.
      find first rsu_mstr
         where rsu_mstr.rsu_index = integer(key_fld[3]) and
               rsu_mstr.rsu_doc_nbr = key_fld[2]
      no-lock no-error.
      find pct_mstr
         where pct_type = ecm_type
           and pct_dsgn_grp = ecm_assign
      no-lock no-error.
      if (available pct_mstr and
         can-find(first rsu_mstr where rsu_mstr.rsu_index = integer(key_fld[3])))
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create rsu_mstr.
         assign
            rsu_doc_nbr  = key_fld[2]
            rsu_index = integer(key_fld[3]).
         import stream ecinout
            rsu_mstr except rsu_doc_nbr rsu_index.
      end.
   end.
   else if key_fld[1] = "type:rsud_det" then do:
      find rsu_mstr where rsu_index = integer(key_fld[3])
      no-lock no-error.
      find ecm_mstr where ecm_nbr = rsu_doc_nbr
      no-lock no-error.
      find pct_mstr where pct_type = ecm_type
         and pct_dsgn_grp = ecm_assign no-lock no-error.
      if (available pct_mstr and
         (not can-find(rstd_det
         where rstd_appr_code = pct_approval
           and rstd_group = key_fld[3])) or
         (can-find(rsud_det where rsud_index = rsu_index
                              and rsud_group = key_fld[2])))
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create rsud_det.
         assign
            rsud_group  = key_fld[2]
            rsud_index  = integer(key_fld[3]).
         import stream ecinout
            rsud_det except rsud_group rsud_index.
         if repro then substring(rsud_group,9,1) = "*".
         else
         if not repro and
            not can-find(first pcl_mstr where
            pcl_group = rsud_group)
         then do:
            delete rsud_det.
            next loop-b.
         end.
         if rsud_cmmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            rsud_cmmtindx = cmtindx.
         end.
         no_rec[4] = no_rec[4] + 1.
      end.
   end.

   else if key_fld[1] = "type:ecd_det" then do:
      if key_fld[4] = "yes"
      then ecdnew = yes.
      else ecdnew = no.
      if can-find(ecd_det where ecd_nbr = key_fld[2] and ecd_part
         = key_fld[3] and ecd_new = ecdnew)
         or not can-find(pt_mstr where pt_part = key_fld[3])
      then do:
         import stream ecinout ^.
         cmtindx = 0.
         next loop-b.
      end.
      else do:
         create ecd_det.
         assign
            ecd_nbr   = key_fld[2]
            ecd_part  = key_fld[3].
         ecd_new = ecdnew.
         import stream ecinout ecd_det except ecd_nbr ecd_part ecd_new.

         if recid(ecd_det) = -1 then.

         if ecd_cmtindx = 0 then cmtindx = 0.
         else do:
            {gprun.i ""eccmtidx.p"" "(output cmtindx)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            ecd_cmtindx = cmtindx.
         end.

         no_rec[6] = no_rec[6] + 1.
      end.
   end.

   else if key_fld[1] = "type:cmt_det" then do:

      if cmtindx = 0 then do:
         import stream ecinout ^.
         next loop-b.
      end.
      else do:
         find cmt_det exclusive-lock
            where cmt_indx = cmtindx
            and cmt_seq = ? no-error.
         if not available cmt_det then do:
            create cmt_det.

            assign cmt_indx   = cmtindx.
            if recid(cmt_det) = -1 then.
         end.
         cmt_seq  = integer(key_fld[3]).
         import stream ecinout cmt_det except cmt_indx cmt_seq.
         no_rec[7] = no_rec[7] + 1.
      end.
   end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

input stream ecinout close.
